/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package forms_control_lesson;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import text_modification.ReadFile;
import text_modification.WritetoFile;
/**
 *
 * @author user
 */
public class FormObject extends javax.swing.JFrame {

    /**
     * Creates new form FormObject
     */
    public FormObject() {
        initComponents();
        GroupButton();
    }
    
    /**
     * Group Button for Radio Button 
     */
    private void GroupButton(){
        ButtonGroup bg1 = new ButtonGroup();
        bg1.add(RadioBtn1);
        bg1.add(RadioBtn2);
        bg1.add(RadioBtn3);
    }
    
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Browser1 = new javax.swing.JFileChooser();
        ComboOne = new javax.swing.JComboBox();
        btnComboBox = new javax.swing.JButton();
        txtComboBoxItem = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        ChkBox1 = new javax.swing.JCheckBox();
        ChkBox2 = new javax.swing.JCheckBox();
        ChkBox3 = new javax.swing.JCheckBox();
        ChkBox4 = new javax.swing.JCheckBox();
        ChkBox5 = new javax.swing.JCheckBox();
        ChkBox6 = new javax.swing.JCheckBox();
        btnChkBox = new javax.swing.JButton();
        txtChkBox = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        RadioBtn1 = new javax.swing.JRadioButton();
        RadioBtn2 = new javax.swing.JRadioButton();
        RadioBtn3 = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        OpenOption = new javax.swing.JMenuItem();
        SaveOption = new javax.swing.JMenuItem();
        CloseOption = new javax.swing.JMenuItem();
        EditMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        ComboOne.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "C Sharp ", "Java", "PHP ", "Android", "VBA ", "Visual Basic .NET" }));

        btnComboBox.setText("Get Drop Down Item");
        btnComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnComboBoxActionPerformed(evt);
            }
        });

        ChkBox1.setText("C Sharp");

        ChkBox2.setText("Java");
        ChkBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ChkBox2ActionPerformed(evt);
            }
        });

        ChkBox3.setText("PHP");
        ChkBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ChkBox3ActionPerformed(evt);
            }
        });

        ChkBox4.setText("Android");

        ChkBox5.setText("VBA");

        ChkBox6.setText("Visual Basics .NET");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ChkBox1)
                    .addComponent(ChkBox3)
                    .addComponent(ChkBox5))
                .addGap(81, 81, 81)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ChkBox6)
                    .addComponent(ChkBox2)
                    .addComponent(ChkBox4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ChkBox1)
                    .addComponent(ChkBox2))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ChkBox3)
                    .addComponent(ChkBox4))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ChkBox5)
                    .addComponent(ChkBox6))
                .addContainerGap(28, Short.MAX_VALUE))
        );

        btnChkBox.setText("Selected Items");
        btnChkBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChkBoxActionPerformed(evt);
            }
        });

        RadioBtn1.setText("Credit Card");

        RadioBtn2.setText("PayPal");

        RadioBtn3.setText("Debit Card ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(RadioBtn1)
                    .addComponent(RadioBtn2)
                    .addComponent(RadioBtn3))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(RadioBtn1)
                .addGap(18, 18, 18)
                .addComponent(RadioBtn2)
                .addGap(18, 18, 18)
                .addComponent(RadioBtn3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setText("Confirm Payment Option");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        FileMenu.setText("File");

        OpenOption.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        OpenOption.setText("Open");
        OpenOption.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OpenOptionActionPerformed(evt);
            }
        });
        FileMenu.add(OpenOption);

        SaveOption.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        SaveOption.setText("Save");
        SaveOption.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveOptionActionPerformed(evt);
            }
        });
        FileMenu.add(SaveOption);

        CloseOption.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        CloseOption.setText("Close");
        FileMenu.add(CloseOption);

        jMenuBar1.add(FileMenu);

        EditMenu.setText("Edit");
        jMenuBar1.add(EditMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ComboOne, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnComboBox)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtComboBoxItem, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtChkBox, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btnChkBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(29, 29, 29)
                                .addComponent(jButton1)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboOne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnComboBox)
                    .addComponent(txtComboBoxItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnChkBox)
                        .addGap(30, 30, 30)
                        .addComponent(txtChkBox, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(40, 40, 40))))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnComboBoxActionPerformed
        String itemText = (String)ComboOne.getSelectedItem();
        txtComboBoxItem.setText(itemText);
    }//GEN-LAST:event_btnComboBoxActionPerformed

    private void ChkBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChkBox3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ChkBox3ActionPerformed

    private void ChkBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChkBox2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ChkBox2ActionPerformed

    private void btnChkBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChkBoxActionPerformed
        String s1 = "";
        if (ChkBox1.isSelected()){
            s1 = s1 + " " + ChkBox1.getText() + "\r\n";
        }
        if (ChkBox2.isSelected()){
            s1 = s1 + " " + ChkBox2.getText() + "\r\n";
        }       
        if (ChkBox3.isSelected()){
            s1 = s1 + " " + ChkBox3.getText() + "\r\n";
        }   
        if (ChkBox4.isSelected()){
            s1 = s1 + " " + ChkBox4.getText() + "\r\n";
        }   
        if (ChkBox5.isSelected()){
            s1 = s1 + " " + ChkBox5.getText() + "\r\n";
        }   
        if (ChkBox6.isSelected()){
            s1 = s1 + " " + ChkBox6.getText() + "\r\n";
        }   
        System.out.println(s1);
        txtChkBox.setText(s1);
    }//GEN-LAST:event_btnChkBoxActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String radioText = "";
        if (RadioBtn1.isSelected()){
            radioText = RadioBtn1.getText();
        }
        if (RadioBtn2.isSelected()){
            radioText = RadioBtn2.getText();
        }
        if (RadioBtn3.isSelected()){
            radioText = RadioBtn3.getText();
        }
        javax.swing.JOptionPane.showMessageDialog(FormObject.this, radioText);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void OpenOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenOptionActionPerformed
        
        FileFilter ff1 = new FileNameExtensionFilter("Text Files", "txt");
        FileFilter ff2 = new FileNameExtensionFilter("Java File", "java");  
        Browser1.addChoosableFileFilter(ff1);
        Browser1.addChoosableFileFilter(ff2);
        
        int returnVal = Browser1.showOpenDialog(this);
        if (returnVal==javax.swing.JFileChooser.APPROVE_OPTION){
            java.io.File file = Browser1.getSelectedFile();
            String file_path = file.toString();
            //JOptionPane.showMessageDialog(FormObject.this, file_path);
            try{
                ReadFile rf = new ReadFile(file_path);
                String[] arrLines = rf.OpenFile();
                int i;
                String textLines = "";
                for (i=0;i<arrLines.length;i++){
                    textLines = textLines + arrLines[i] + '\n';
                }
                System.out.println(textLines);
                JOptionPane.showMessageDialog(FormObject.this, textLines);
            }
            catch(java.io.IOException e){
                System.out.println(e.getMessage());
            }
            
        }
    }//GEN-LAST:event_OpenOptionActionPerformed

    private void SaveOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveOptionActionPerformed
        FileFilter ff1 = new FileNameExtensionFilter("Text File", "txt");
        FileFilter ff2 = new FileNameExtensionFilter("Java File", "java");
        Browser1.addChoosableFileFilter(ff1);
        Browser1.addChoosableFileFilter(ff2);
        int returnVal = Browser1.showSaveDialog(this);
        if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION){
            java.io.File File = Browser1.getSelectedFile();
            String file_path = File.toString();
            try{
                WritetoFile wf = new WritetoFile(file_path, true);
                String alltext = "\r\n" + txtChkBox.getText();
                wf.Writing(alltext);
            }
            catch(java.io.IOException e){
                System.out.println(e.getMessage());
            }
        }
        
    }//GEN-LAST:event_SaveOptionActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormObject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormObject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormObject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormObject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormObject().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser Browser1;
    private javax.swing.JCheckBox ChkBox1;
    private javax.swing.JCheckBox ChkBox2;
    private javax.swing.JCheckBox ChkBox3;
    private javax.swing.JCheckBox ChkBox4;
    private javax.swing.JCheckBox ChkBox5;
    private javax.swing.JCheckBox ChkBox6;
    private javax.swing.JMenuItem CloseOption;
    private javax.swing.JComboBox ComboOne;
    private javax.swing.JMenu EditMenu;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JMenuItem OpenOption;
    private javax.swing.JRadioButton RadioBtn1;
    private javax.swing.JRadioButton RadioBtn2;
    private javax.swing.JRadioButton RadioBtn3;
    private javax.swing.JMenuItem SaveOption;
    private javax.swing.JButton btnChkBox;
    private javax.swing.JButton btnComboBox;
    private javax.swing.JButton jButton1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField txtChkBox;
    private javax.swing.JTextField txtComboBoxItem;
    // End of variables declaration//GEN-END:variables
}
